package com.qudian.java.core.common.exception;

import org.apache.commons.lang.StringUtils;

public enum ResponseCodeEnum {

    SYS_ERROR_0001("SYS_ERROR_0001", "系统错误：网络开小差"),

    BIZ_ERROR_0001("BIZ_ERROR_0001", "不能为空"),
    BIZ_FileNotNull("BIZ_ERROR_0002", "文件不能为空"),
    BIZ_UPLOAD_SUCCESS("1", "上传成功"),
    BIZ_UPLOAD_ERROR("BIZ_ERROR_0004", "上传出错"),
    BIZ_CANSHU_ERROR("BIZ_ERROR_0005", "参数有误"),
    BIZ_FILEING_ERROR("BIZ_ERROR_0006", "文件准备中,稍后再试!"),
    BIZ_FILENOTBAKE_ERROR("BIZ_ERROR_0007", "包状态不为已回传!,赎回失败"),
    BIZ_RCCODEIS_ERROR("BIZ_ERROR_0008", "任务已存在!,赎回失败"),

    BIZ_P2PPLATFORM_NOTNULL("BIZ_ERROR_0009", "推标平台不能为空"),
    BIZ_REDEEMDAY_NOTNULL("BIZ_ERROR_0010", "赎回日不能为空"),
    BIZ_ENDBILLDAY_NOTNULL("BIZ_ERROR_0011", "截止账单日不能为空"),
    BIZ_BUSSINESS_NOTNULL("BIZ_ERROR_0012", "业务线不能为空"),
    BIZ_FINANCECAPITAL_NOTNULL("BIZ_ERROR_0013", "财务支付本金不能为空"),
    BIZ_FINANCEINTEREST_NOTNULL("BIZ_ERROR_0014", "财务支付利息不能为空"),
    BIZ_PAYAREA_NOTNULL("BIZ_ERROR_0015", "订单归属不能为空"),
    BIZ_ORDERTYPE_NOTNULL("BIZ_ERROR_0016", "订单类型不能为空"),
    BIZ_PUSHMARKNUM_NOTNULL("BIZ_ERROR_0017", "推标期数不能为空"),
    BIZ_USERNAME_NOTNULL("BIZ_ERROR_0018", "用户名不能为空"),
    BIZ_USERID_NOTNULL("BIZ_ERROR_0019", "用户ID不能为空"),
    BIZ_REPAYCYCLEDAY_NOTNULL("BIZ_ERROR_0020", "请填写用户还款周期调整的天数"),
    BIZ_REPAYP2PDAY_NOTNULL("BIZ_ERROR_0021", "请填写P2P还款日类型调整的天数"),
    BIZ_P2PTYPE_NOTNULL("BIZ_ERROR_0022", "已选择[P2P还款日类型]为'按订单还款日',请选择[按用户账单日] 还是 [按上期还款日]"),
    BIZ_NOTFINDPACKAGE("BIZ_ERROR_0023", "查询不到相关资产包"),
    BIZ_STATUSERROR("BIZ_ERROR_0024", "资产包状态非等待回传"),
    BIZ_P2PPLATFORMERROR("BIZ_ERROR_0025", "推标平台不一致,请修改后重试"),
    BIZ_BUSSNIESSERROR("BIZ_ERROR_0026", "业务类型不一致,请修改后重试"),
    BIZ_PAYERROR("BIZ_ERROR_0027", "订单归属不一致,请修改后重试"),
    BIZ_FIRSTDEADLINEUP("BIZ_ERROR_0028", "首期账单日区间填写有误,首期账单日应小于下个月今天的前一天"),
    BIZ_FIRSTDEADLINEDOWN("BIZ_ERROR_0029", "首期账单日必须大于今天"),
    BIZ_RRDEEMDATEERROR("BIZ_ERROR_0030", "赎回日必须大于等于今天"),
    BIZ_ENDBLILYDAY("BIZ_ERROR_0031", "截止账单日必须大于赎回日"),
    BIZ_ENDBLILYDAYANDREDEEMDAY("BIZ_ERROR_0032", "赎回日与截止账单日相差不得大于一个月"),
    BIZ_IDNOTMULL("BIZ_ERROR_0030", "id 不能为空"),
    BIZ_NOTFOUND("BIZ_ERROR_0031", "没有找到该条数据"),
    BIZ_INSERTERROR("BIZ_ERROR_0032", "插入失败"),
    BIZ_UPDATEERROR("BIZ_ERROR_0033", "更新失败"),
    BIZ_DELERROR("BIZ_ERROR_0034", "删除失败"),
    BIZ_BGANDED("BIZ_ERROR_0035", "开始日期与结束日期最大不能相差6个月"),
    BIZ_EndTIMENOTNULL("BIZ_ERROR_0036", "结束日期不能为空"),
    BIZ_BGANDEDSUB("BIZ_ERROR_0037", "开始日期与结束日期最小不能相差1个月"),
    BIZ_INSERTABSTASKOVERVIEWERROR("BIZ_ERROR_0037", "开始日期与结束日期最小不能相差1个月"),
    BIZ_OPERATION_SUCCESS("1", "操作成功"),

    BIZ_FILE_UPLOADSUCCESS("1", "文件上传成功"),
    BIZ_FILE_ISDONE("1", "文件准备完成"),
    SYS_SUCCESS_SAVE("1", "保存成功"),
    SYS_INVALID("1", "作废成功"),;

    private String code;
    private String msg;

    private ResponseCodeEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static String getNameByCode(String code) {
        if (StringUtils.isBlank(code)) return null;
        for (ResponseCodeEnum accountInfoEnum : ResponseCodeEnum.values()) {
            if (code.equals(accountInfoEnum.getCode())) {
                return accountInfoEnum.getMsg();
            }
        }
        return null;
    }

    public static String getCodeByName(String name) {
        if (StringUtils.isBlank(name)) return null;
        for (ResponseCodeEnum accountInfoEnum : ResponseCodeEnum.values()) {
            if (name.equals(accountInfoEnum.getMsg())) {
                return accountInfoEnum.getCode();
            }
        }
        return null;
    }
}
